package com.thouiot.test.modbus.controller;

import com.thouiot.common.result.ResultUtil;
import com.thouiot.common.result.TiotResult;
import com.thouiot.modbus.entity.vo.ModbusLocatorVo;
import com.thouiot.modbus.service.ISlaveService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @description modbus slave 操作控制器
 * @author wangkai
 * @date 2025/04/17 09:38
 */
@RestController
@RequestMapping("/modbus-slave")
public class ModbusSlaveController {

    @Resource
    private ISlaveService slaveService;

    /**
     * 写入modbus slave
     * @param locator
     * @return
     */
    @PostMapping("/write")
    public TiotResult write(@RequestBody ModbusLocatorVo locator) {
        slaveService.writeSlave(locator);
        return ResultUtil.builderSuccessResult(null);
    }

    /**
     * 读取modbus slave
     * @param locator
     * @return
     */
    @PostMapping("/read")
    public TiotResult read(@RequestBody ModbusLocatorVo locator) {
        return ResultUtil.builderSuccessResult(slaveService.readSlaveStatus(locator));
    }
}
